package com.taobao.home.feignclient;

import com.taobao.base.model.RestResponse;
import com.taobao.home.model.dto.GoodsDetailsDto;
import com.taobao.home.model.dto.GoodsPreviewDto1;
import com.taobao.home.model.po.Goods;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Slf4j
@Component
public class SearchServiceClientFallbackFactory implements FallbackFactory<SearchServiceClient> {



    @Override
    public SearchServiceClient create(Throwable cause) {

        return new SearchServiceClient() {
            @Override
            public RestResponse<String> addDoc(Goods goods) {
                log.error("添加课程索引发生熔断,索引信息:{},熔断异常:{}",goods,cause.toString(),cause);
                //走降级了返回 false
                return RestResponse.validfail("添加课程索引发生熔断,熔断异常:"+cause.toString());
            }

            @Override
            public RestResponse<String> test(int goodsId) {
                return null;
            }

            @Override
            public RestResponse<List<GoodsDetailsDto>> goodsDetailsByTitle(String title) {
                log.error("添加课程索引发生熔断,索引信息:{},熔断异常:{}",title,cause.toString(),cause);
                //走降级了返回 false
                return RestResponse.validfail("添加课程索引发生熔断,熔断异常:"+cause.toString());
            }

            @Override
            public RestResponse<List<GoodsPreviewDto1>> getGoodsPreviewByTitle(String title) {
                log.error("添加课程索引发生熔断,索引信息:{},熔断异常:{}",title,cause.toString(),cause);
                //走降级了返回 false
                return RestResponse.validfail("添加课程索引发生熔断,熔断异常:"+cause.toString());
            }

        };
    }
}
